/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import biz.AboutUsBO;
import biz.AccountBO;
import biz.BranchBO;
import biz.FitnessProgramBO;
import biz.NutritionZoneBO;
import biz.SuccessStoryBO;
import biz.UserDetailBO;
import entity.AboutUs;
import entity.Account;
import entity.Branch;
import entity.FitnessProgram;
import entity.NutritionZone;
import entity.SuccessStory;
import entity.UserDetail;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Window;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.border.LineBorder;

/**
 *
 * @author Administrator
 */
public class Main extends javax.swing.JFrame {
    
    private MListModel<FitnessProgram> mlmFitness;
    private MListModel<NutritionZone> mlmNutrition;
    private MListModel<SuccessStory> mlmSuccess;
    private MListModel<Branch> mlmBranch;
    private ArrayList<AboutUs> arrAboutUs;
    private ControlPanel controlPanel;
    private int curAccLv = -1;
    private UserDetail curUser;
    private MTimerTask Newsfeed;
    private Timer timer;
    private Main parent;

    /**
     * Creates new form Main
     */
    public Main() {
        initComponents();
        this.setFullScreen();
        curAccLv = -1;
        timer = new Timer();
        Newsfeed = new MTimerTask(this, lblNEContent, lblNEPicture);
        timer.schedule(Newsfeed, 0, 500);
        lstFitness.setCellRenderer(new MCellRenderer(Color.decode("#094EB6"), Color.decode("#2C88EE"), 1));
        lstFitness.setBackground(Color.decode("#2C88EE"));
        lstNutrition.setCellRenderer(new MCellRenderer(Color.decode("#004050"), Color.decode("#009DAF"), 1));
        lstNutrition.setBackground(Color.decode("#009DAF"));
        lstSuccess.setCellRenderer(new MCellRenderer(Color.decode("#5435AE"), Color.decode("#A400AB"), 1));
        lstSuccess.setBackground(Color.decode("#A400AB"));
        lstFitness.setFixedCellHeight(lstFitness.getHeight() / 5);
        lstNutrition.setFixedCellHeight(lstNutrition.getHeight() / 5);
        lstSuccess.setFixedCellHeight(lstSuccess.getHeight() / 5);
        lstBranch.setFixedCellHeight(lstBranch.getHeight());
        
        this.loadData();
        
        
        
        lstBranch.setCellRenderer(new MCellRenderer(Color.decode("#008D00"), Color.decode("#4B7C88"), 0));
        lstBranch.setBackground(Color.decode("#4B7C88"));
        
    }
    
    public final void loadData() {
        try {
            mlmFitness = new MListModel<FitnessProgram>((new FitnessProgramBO()).getAllFitnessProgram());
            lstFitness.setModel(mlmFitness);
            
            mlmNutrition = new MListModel<NutritionZone>((new NutritionZoneBO()).getAllNutritionZone());
            lstNutrition.setModel(mlmNutrition);
            
            mlmSuccess = new MListModel<SuccessStory>((new SuccessStoryBO()).getAllSuccessStory());
            lstSuccess.setModel(mlmSuccess);
            
            mlmBranch = new MListModel<Branch>(new BranchBO().getAllBranch());
            lstBranch.setModel(mlmBranch);
            timer.cancel();
            timer = new Timer();
            Newsfeed = new MTimerTask(this, lblNEContent, lblNEPicture);
            timer.schedule(Newsfeed, 0, 500);
            
            if (curUser != null) {
                curUser = new UserDetailBO().getByUName(txtUserName.getText());
                lblUserInfo.setText(curUser.toString());
            } else {
                lblUserInfo.setText("");
            }
            arrAboutUs = (new AboutUsBO()).getAllAboutUs();
            if (arrAboutUs.size() > 0) {
                txtAboutUs.setText(arrAboutUs.get(0).toString());
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(this, "Error: Database Link Error", "Message Dialog", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    public int getCurAccLv() {
        return curAccLv;
    }
    
    private void setFullScreen() {
        dispose();
        Toolkit tk = Toolkit.getDefaultToolkit();
        int xSize = ((int) tk.getScreenSize().getWidth());
        int ySize = ((int) tk.getScreenSize().getHeight());
        getContentPane().setBackground(Color.BLACK);
        setSize(xSize, ySize);
        //jDialog1.setSize((int)(xSize*0.6), (int) (ySize*0.6));
        //setAlwaysOnTop(true);
        setUndecorated(true);
        setVisible(true);
        lblNEPicture.setSize(lpnNE.getSize());
        pnlLogin.setSize(jLayeredPane2.getSize());
        pnlUserDetail.setSize(jLayeredPane2.getSize());
        lblNEContent.setSize(lpnNE.getSize());
        revalidate();
    }
    
    public void setupDialog(JDialog dialog) {
        dialog.dispose();
        dialog.setUndecorated(true);
        dialog.setSize((int) (this.getWidth() * 0.6), (int) (this.getHeight() * 0.6));
        dialog.setLocation((int) (this.getWidth() * 0.2), (int) (this.getHeight() * 0.2));
        dialog.setVisible(true);
        dialog.getRootPane().setBorder(new LineBorder(Color.yellow, 1));
    }
    
    public MListModel<FitnessProgram> getMlmFitness() {
        return mlmFitness;
    }
    
    public MListModel<NutritionZone> getMlmNutrition() {
        return mlmNutrition;
    }
    
    public MListModel<SuccessStory> getMlmSuccess() {
        return mlmSuccess;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlBranches = new javax.swing.JPanel();
        scrlBranch = new javax.swing.JScrollPane();
        lstBranch = new javax.swing.JList();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        pnlLogin = new javax.swing.JPanel();
        lblUserName = new javax.swing.JLabel();
        txtUserName = new javax.swing.JTextField();
        lblPassword = new javax.swing.JLabel();
        btnLogin = new javax.swing.JButton();
        pswPassword = new javax.swing.JPasswordField();
        lblRegister = new javax.swing.JLabel();
        pnlUserDetail = new javax.swing.JPanel();
        lblUserInfo = new javax.swing.JLabel();
        pnlAdminControl = new javax.swing.JPanel();
        btnAddFitness = new javax.swing.JButton();
        btnAddNutri = new javax.swing.JButton();
        btnAddSuccess = new javax.swing.JButton();
        btnAddBranch = new javax.swing.JButton();
        btnAddEvent = new javax.swing.JButton();
        pnlAboutUs = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAboutUs = new javax.swing.JTextArea();
        pnlNutritionZone = new javax.swing.JPanel();
        scrpNutritionZone = new javax.swing.JScrollPane();
        lstNutrition = new javax.swing.JList();
        pnlSuccessStories = new javax.swing.JPanel();
        scrpSuccessStories = new javax.swing.JScrollPane();
        lstSuccess = new javax.swing.JList();
        pnlFitnessProgram = new javax.swing.JPanel();
        scrpFitnessProgram = new javax.swing.JScrollPane();
        lstFitness = new javax.swing.JList();
        lpnNE = new javax.swing.JLayeredPane();
        lblNEContent = new javax.swing.JLabel();
        lblNEPicture = new javax.swing.JLabel();
        mnbPrimePhysique = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(204, 204, 204));
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        pnlBranches.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        scrlBranch.setBorder(null);

        lstBranch.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstBranch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstBranchMouseClicked(evt);
            }
        });
        scrlBranch.setViewportView(lstBranch);

        javax.swing.GroupLayout pnlBranchesLayout = new javax.swing.GroupLayout(pnlBranches);
        pnlBranches.setLayout(pnlBranchesLayout);
        pnlBranchesLayout.setHorizontalGroup(
            pnlBranchesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBranchesLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(scrlBranch, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE))
        );
        pnlBranchesLayout.setVerticalGroup(
            pnlBranchesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlBranch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
        );

        pnlLogin.setBackground(new java.awt.Color(176, 26, 64));
        pnlLogin.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlLogin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pnlLoginMouseClicked(evt);
            }
        });

        lblUserName.setForeground(new java.awt.Color(255, 255, 255));
        lblUserName.setText("User Name:");

        lblPassword.setForeground(new java.awt.Color(255, 255, 255));
        lblPassword.setText("Password:");

        btnLogin.setText("Login");
        btnLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoginActionPerformed(evt);
            }
        });

        lblRegister.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblRegister.setForeground(new java.awt.Color(255, 255, 255));
        lblRegister.setText("<html><u>Register new account?</u></html>");
        lblRegister.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblRegisterMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout pnlLoginLayout = new javax.swing.GroupLayout(pnlLogin);
        pnlLogin.setLayout(pnlLoginLayout);
        pnlLoginLayout.setHorizontalGroup(
            pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLoginLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                    .addComponent(lblPassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLoginLayout.createSequentialGroup()
                        .addComponent(lblRegister, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(pnlLoginLayout.createSequentialGroup()
                        .addGroup(pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlLoginLayout.createSequentialGroup()
                                .addComponent(btnLogin)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(txtUserName)
                            .addComponent(pswPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                        .addGap(21, 21, 21))))
        );
        pnlLoginLayout.setVerticalGroup(
            pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLoginLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUserName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPassword)
                    .addComponent(pswPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnLogin)
                .addGap(17, 17, 17)
                .addComponent(lblRegister, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(73, 73, 73))
        );

        pnlLogin.setBounds(0, 0, 280, 200);
        jLayeredPane2.add(pnlLogin, javax.swing.JLayeredPane.DEFAULT_LAYER);

        pnlUserDetail.setBackground(new java.awt.Color(176, 26, 64));

        lblUserInfo.setText("jLabel4");
        lblUserInfo.setAlignmentY(0.0F);
        lblUserInfo.setIconTextGap(0);
        lblUserInfo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblUserInfoMouseClicked(evt);
            }
        });

        pnlAdminControl.setBackground(new java.awt.Color(255, 153, 153));
        pnlAdminControl.setLayout(new java.awt.GridLayout(5, 1));

        btnAddFitness.setBackground(new java.awt.Color(255, 153, 153));
        btnAddFitness.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAddFitness.setForeground(new java.awt.Color(102, 0, 102));
        btnAddFitness.setText("Fitness");
        btnAddFitness.setBorder(null);
        btnAddFitness.setBorderPainted(false);
        btnAddFitness.setOpaque(false);
        btnAddFitness.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddFitnessActionPerformed(evt);
            }
        });
        pnlAdminControl.add(btnAddFitness);

        btnAddNutri.setBackground(new java.awt.Color(255, 153, 153));
        btnAddNutri.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAddNutri.setForeground(new java.awt.Color(102, 0, 102));
        btnAddNutri.setText("Nutrition");
        btnAddNutri.setBorder(null);
        btnAddNutri.setBorderPainted(false);
        btnAddNutri.setOpaque(false);
        btnAddNutri.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddNutriActionPerformed(evt);
            }
        });
        pnlAdminControl.add(btnAddNutri);

        btnAddSuccess.setBackground(new java.awt.Color(255, 153, 153));
        btnAddSuccess.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAddSuccess.setForeground(new java.awt.Color(102, 0, 102));
        btnAddSuccess.setText("Success");
        btnAddSuccess.setBorder(null);
        btnAddSuccess.setBorderPainted(false);
        btnAddSuccess.setOpaque(false);
        btnAddSuccess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSuccessActionPerformed(evt);
            }
        });
        pnlAdminControl.add(btnAddSuccess);

        btnAddBranch.setBackground(new java.awt.Color(255, 153, 153));
        btnAddBranch.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAddBranch.setForeground(new java.awt.Color(102, 0, 102));
        btnAddBranch.setText("Branch");
        btnAddBranch.setBorder(null);
        btnAddBranch.setBorderPainted(false);
        btnAddBranch.setOpaque(false);
        btnAddBranch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddBranchActionPerformed(evt);
            }
        });
        pnlAdminControl.add(btnAddBranch);

        btnAddEvent.setBackground(new java.awt.Color(255, 153, 153));
        btnAddEvent.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAddEvent.setForeground(new java.awt.Color(102, 0, 102));
        btnAddEvent.setText("Event");
        btnAddEvent.setBorder(null);
        btnAddEvent.setBorderPainted(false);
        btnAddEvent.setOpaque(false);
        btnAddEvent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddEventActionPerformed(evt);
            }
        });
        pnlAdminControl.add(btnAddEvent);

        javax.swing.GroupLayout pnlUserDetailLayout = new javax.swing.GroupLayout(pnlUserDetail);
        pnlUserDetail.setLayout(pnlUserDetailLayout);
        pnlUserDetailLayout.setHorizontalGroup(
            pnlUserDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlUserDetailLayout.createSequentialGroup()
                .addComponent(lblUserInfo, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlAdminControl, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        pnlUserDetailLayout.setVerticalGroup(
            pnlUserDetailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblUserInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlAdminControl, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
        );

        pnlUserDetail.setBounds(0, 0, 240, 190);
        jLayeredPane2.add(pnlUserDetail, javax.swing.JLayeredPane.DEFAULT_LAYER);

        pnlAboutUs.setBackground(new java.awt.Color(218, 84, 45));
        pnlAboutUs.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jScrollPane1.setBorder(null);
        jScrollPane1.setForeground(new java.awt.Color(255, 255, 255));

        txtAboutUs.setEditable(false);
        txtAboutUs.setBackground(new java.awt.Color(218, 84, 45));
        txtAboutUs.setColumns(20);
        txtAboutUs.setForeground(new java.awt.Color(255, 255, 255));
        txtAboutUs.setLineWrap(true);
        txtAboutUs.setRows(5);
        txtAboutUs.setText("ádsd");
        txtAboutUs.setAlignmentX(10.0F);
        txtAboutUs.setAlignmentY(10.0F);
        txtAboutUs.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10)));
        txtAboutUs.setMargin(new java.awt.Insets(10, 10, 10, 10));
        txtAboutUs.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtAboutUsFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtAboutUsFocusLost(evt);
            }
        });
        jScrollPane1.setViewportView(txtAboutUs);

        javax.swing.GroupLayout pnlAboutUsLayout = new javax.swing.GroupLayout(pnlAboutUs);
        pnlAboutUs.setLayout(pnlAboutUsLayout);
        pnlAboutUsLayout.setHorizontalGroup(
            pnlAboutUsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        pnlAboutUsLayout.setVerticalGroup(
            pnlAboutUsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
        );

        pnlNutritionZone.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        scrpNutritionZone.setBorder(null);

        lstNutrition.setBackground(new java.awt.Color(0, 0, 0));
        lstNutrition.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstNutrition.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstNutritionMouseClicked(evt);
            }
        });
        scrpNutritionZone.setViewportView(lstNutrition);

        javax.swing.GroupLayout pnlNutritionZoneLayout = new javax.swing.GroupLayout(pnlNutritionZone);
        pnlNutritionZone.setLayout(pnlNutritionZoneLayout);
        pnlNutritionZoneLayout.setHorizontalGroup(
            pnlNutritionZoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrpNutritionZone, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
        );
        pnlNutritionZoneLayout.setVerticalGroup(
            pnlNutritionZoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrpNutritionZone, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
        );

        pnlSuccessStories.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        scrpSuccessStories.setBorder(null);

        lstSuccess.setBackground(new java.awt.Color(0, 0, 0));
        lstSuccess.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstSuccess.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstSuccessMouseClicked(evt);
            }
        });
        scrpSuccessStories.setViewportView(lstSuccess);

        javax.swing.GroupLayout pnlSuccessStoriesLayout = new javax.swing.GroupLayout(pnlSuccessStories);
        pnlSuccessStories.setLayout(pnlSuccessStoriesLayout);
        pnlSuccessStoriesLayout.setHorizontalGroup(
            pnlSuccessStoriesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrpSuccessStories, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
        );
        pnlSuccessStoriesLayout.setVerticalGroup(
            pnlSuccessStoriesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrpSuccessStories, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
        );

        pnlFitnessProgram.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        scrpFitnessProgram.setBorder(null);

        lstFitness.setBackground(new java.awt.Color(0, 0, 0));
        lstFitness.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "<html><b>Item 1</b></html>", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        lstFitness.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lstFitnessMouseClicked(evt);
            }
        });
        scrpFitnessProgram.setViewportView(lstFitness);

        javax.swing.GroupLayout pnlFitnessProgramLayout = new javax.swing.GroupLayout(pnlFitnessProgram);
        pnlFitnessProgram.setLayout(pnlFitnessProgramLayout);
        pnlFitnessProgramLayout.setHorizontalGroup(
            pnlFitnessProgramLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrpFitnessProgram, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
        );
        pnlFitnessProgramLayout.setVerticalGroup(
            pnlFitnessProgramLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrpFitnessProgram, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
        );

        lblNEContent.setText("jLabel1");
        lblNEContent.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        lblNEContent.setAlignmentY(0.0F);
        lblNEContent.setBounds(0, 0, 1030, 280);
        lpnNE.add(lblNEContent, javax.swing.JLayeredPane.MODAL_LAYER);

        lblNEPicture.setBackground(new java.awt.Color(204, 204, 204));
        lblNEPicture.setText("jLabel3");
        lblNEPicture.setOpaque(true);
        lblNEPicture.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblNEPictureMouseClicked(evt);
            }
        });
        lblNEPicture.setBounds(0, 0, 1030, 280);
        lpnNE.add(lblNEPicture, javax.swing.JLayeredPane.PALETTE_LAYER);

        jMenu1.setText("File");

        jMenuItem2.setText("Log out");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem1.setText("Exit");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        mnbPrimePhysique.add(jMenu1);

        setJMenuBar(mnbPrimePhysique);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnlFitnessProgram, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlNutritionZone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlSuccessStories, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lpnNE, javax.swing.GroupLayout.PREFERRED_SIZE, 1029, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLayeredPane2)
                    .addComponent(pnlAboutUs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlBranches, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lpnNE, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnlBranches, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlSuccessStories, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlNutritionZone, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlFitnessProgram, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLayeredPane2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlAboutUs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jMenuItem1ActionPerformed
    
    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
        //jDialog1.dispose();
        Window[] windows = getWindows();
        for (int i = 0; i < windows.length; i++) {
            if (windows[i] != this) {
                windows[i].dispose();
            }
        }
    }//GEN-LAST:event_formWindowGainedFocus
    
    private void lstFitnessMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstFitnessMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            if (lstFitness.getSelectedIndex() >= 0) {
                FitnessProgram data = mlmFitness.getObject(lstFitness.getSelectedIndex());
                DialogFitness dialog;
                switch (curAccLv) {
                    case 0: {
                        dialog = new DialogFitness(this, false, DialogFitness.REG, data);
                        dialog.setUserid(curUser.getId());
                    }
                    break;
                    
                    case 1:
                    case -1:
                    default: {
                        dialog = new DialogFitness(this, false, DialogFitness.SHOW, data);
                    }
                    break;
                    case 2: {
                        dialog = new DialogFitness(this, false, DialogFitness.EDIT, data);
                    }
                    break;
                }
                setupDialog(dialog);
            }
        }
    }//GEN-LAST:event_lstFitnessMouseClicked
    
    private void lstNutritionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstNutritionMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            if (lstNutrition.getSelectedIndex() >= 0) {
                NutritionZone data = mlmNutrition.getObject(lstNutrition.getSelectedIndex());
                DialogNutritionZone dialog;
                switch (curAccLv) {
                    
                    case 0:
                    case 1:
                    default: {
                        dialog = new DialogNutritionZone(this, false, DialogNutritionZone.SHOW, data);
                    }
                    break;
                    case 2: {
                        dialog = new DialogNutritionZone(this, false, DialogNutritionZone.EDIT, data);
                    }
                    break;
                }
                setupDialog(dialog);
            }
        }
    }//GEN-LAST:event_lstNutritionMouseClicked
    
    private void lstSuccessMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstSuccessMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            if (lstSuccess.getSelectedIndex() >= 0) {
                SuccessStory data = mlmSuccess.getObject(lstSuccess.getSelectedIndex());
                DialogSuccess dialog;
                switch (curAccLv) {
                    
                    case 0:
                    case 1:
                    default: {
                        dialog = new DialogSuccess(this, false, DialogSuccess.SHOW, data);
                    }
                    break;
                    case 2: {
                        dialog = new DialogSuccess(this, false, DialogSuccess.EDIT, data);
                    }
                    break;
                }
                setupDialog(dialog);
            }
        }
    }//GEN-LAST:event_lstSuccessMouseClicked
    
    private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoginActionPerformed
        try {
            // TODO add your handling code here:
            Account curAcc = new AccountBO().checkPassword(txtUserName.getText(), new String(pswPassword.getPassword()));
            if (curAcc != null) {
                pnlLogin.setVisible(false);
                pnlUserDetail.setVisible(true);
                jLayeredPane2.setPosition(pnlUserDetail, 0);
                curUser = new UserDetailBO().getByUName(txtUserName.getText());
                lblUserInfo.setText(curUser.toString());
                
                curAccLv = curAcc.getLevel();
                switch (curAccLv) {
                    default:
                    case -1:
                        {
                        controlPanel = new ControlPanel(this, false, -1, curUser);
                        pnlAdminControl.setVisible(false);
                    }
                    case 0: {
                        controlPanel = new ControlPanel(this, false, 0, curUser);
                        pnlAdminControl.setVisible(false);
                    }
                    break;
                    case 1: {
                        controlPanel = new ControlPanel(this, false, 1, curUser);
                        pnlAdminControl.setVisible(false);
                    }
                    break;
                    case 2: {
                        controlPanel = new ControlPanel(this, false, 2, curUser);
                        pnlAdminControl.setVisible(true);
                    }
                    break;
                }
            } else {
                JOptionPane.showMessageDialog(controlPanel, "Username not exist or wrong password");
            }
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_btnLoginActionPerformed
    
    private void lblUserInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblUserInfoMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            setupDialog(controlPanel);
        }
    }//GEN-LAST:event_lblUserInfoMouseClicked
    
    private void pnlLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLoginMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_pnlLoginMouseClicked
    
    private void btnAddFitnessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFitnessActionPerformed
        // TODO add your handling code here:
        DialogFitness dialog = new DialogFitness(this, false, DialogFitness.ADD, null);
        setupDialog(dialog);
    }//GEN-LAST:event_btnAddFitnessActionPerformed
    
    private void btnAddNutriActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddNutriActionPerformed
        // TODO add your handling code here:
        DialogNutritionZone dialog = new DialogNutritionZone(this, false, DialogNutritionZone.ADD, null);
        setupDialog(dialog);
    }//GEN-LAST:event_btnAddNutriActionPerformed
    
    private void btnAddSuccessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSuccessActionPerformed
        // TODO add your handling code here:
        DialogSuccess dialog = new DialogSuccess(this, false, DialogSuccess.ADD, null);
        setupDialog(dialog);
    }//GEN-LAST:event_btnAddSuccessActionPerformed
    
    private void lblRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblRegisterMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            JDialog dialog = new JDialog(this);
            dialog.setContentPane(new PanelPersonalInfo(this, null, PanelPersonalInfo.ADD));
            InstallEsc.installEscapeCloseOperation(dialog);
            setupDialog(dialog);
        }
    }//GEN-LAST:event_lblRegisterMouseClicked
    
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        pnlLogin.setVisible(true);
        pnlUserDetail.setVisible(false);
        jLayeredPane2.setPosition(pnlLogin, 0);
        curAccLv = -1;
        curUser = null;
    }//GEN-LAST:event_jMenuItem2ActionPerformed
    
    private void lblNEPictureMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblNEPictureMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_lblNEPictureMouseClicked
    
    private void btnAddBranchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddBranchActionPerformed
        // TODO add your handling code here:
        DialogBranch dialog = new DialogBranch(this, false, DialogBranch.ADD, null);
        setupDialog(dialog);
        
    }//GEN-LAST:event_btnAddBranchActionPerformed
    
    private void btnAddEventActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddEventActionPerformed
        // TODO add your handling code here:
        DialogNewEvents dialog = new DialogNewEvents(this, false, DialogNewEvents.ADD, null);
        setupDialog(dialog);
    }//GEN-LAST:event_btnAddEventActionPerformed
    
    private void lstBranchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstBranchMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            if (lstBranch.getSelectedIndex() >= 0) {
                Branch data = mlmBranch.getObject(lstBranch.getSelectedIndex());
                DialogBranch dialog;
                switch (curAccLv) {
                    
                    case 0:
                    case 1:
                    default: {
                        dialog = new DialogBranch(this, false, DialogBranch.SHOW, data);
                    }
                    break;
                    case 2: {
                        dialog = new DialogBranch(this, false, DialogBranch.EDIT, data);
                    }
                    break;
                }
                setupDialog(dialog);
            }
        }
    }//GEN-LAST:event_lstBranchMouseClicked
        
    private void txtAboutUsFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtAboutUsFocusGained
        // TODO add your handling code here:
        if (curAccLv == 2) {
            txtAboutUs.setEditable(true);
        }
    }//GEN-LAST:event_txtAboutUsFocusGained
    
    private void txtAboutUsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtAboutUsFocusLost
        // TODO add your handling code here:
        if (curAccLv == 2) {
            txtAboutUs.setEditable(false);
            txtAboutUs.setFocusable(false);
            try {   // TODO add your handling code here:
                int i = JOptionPane.showConfirmDialog(this, "Do you want to Alter this record into database?", "Comfirm Dialog ", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (i == JOptionPane.YES_OPTION) // neu nguoi dung chon "Yes"
                {
                    new AboutUsBO().editAboutUs(new AboutUs(1, txtAboutUs.getText()));
                    JOptionPane.showMessageDialog(this, "Alter successful", "Message Dialog Demo", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    this.loadData();
                }
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(this, "Error: Database Link Error", "Message Dialog", JOptionPane.ERROR_MESSAGE);
            }
            txtAboutUs.setFocusable(true);
        }
    }//GEN-LAST:event_txtAboutUsFocusLost

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new Main();
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddBranch;
    private javax.swing.JButton btnAddEvent;
    private javax.swing.JButton btnAddFitness;
    private javax.swing.JButton btnAddNutri;
    private javax.swing.JButton btnAddSuccess;
    private javax.swing.JButton btnLogin;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblNEContent;
    private javax.swing.JLabel lblNEPicture;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblRegister;
    private javax.swing.JLabel lblUserInfo;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JLayeredPane lpnNE;
    private javax.swing.JList lstBranch;
    private javax.swing.JList lstFitness;
    private javax.swing.JList lstNutrition;
    private javax.swing.JList lstSuccess;
    private javax.swing.JMenuBar mnbPrimePhysique;
    private javax.swing.JPanel pnlAboutUs;
    private javax.swing.JPanel pnlAdminControl;
    private javax.swing.JPanel pnlBranches;
    private javax.swing.JPanel pnlFitnessProgram;
    private javax.swing.JPanel pnlLogin;
    private javax.swing.JPanel pnlNutritionZone;
    private javax.swing.JPanel pnlSuccessStories;
    private javax.swing.JPanel pnlUserDetail;
    private javax.swing.JPasswordField pswPassword;
    private javax.swing.JScrollPane scrlBranch;
    private javax.swing.JScrollPane scrpFitnessProgram;
    private javax.swing.JScrollPane scrpNutritionZone;
    private javax.swing.JScrollPane scrpSuccessStories;
    private javax.swing.JTextArea txtAboutUs;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
}
